package com.wx.cloud.sign.controller;

import com.wx.cloud.sign.common.CommonResult;
import com.wx.cloud.sign.model.Page;
import com.wx.cloud.sign.model.Sign;
import com.wx.cloud.sign.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sign")
public class SignController {

    @Autowired
    private SignService signService;

    @PostMapping("/addSign")
    public CommonResult addSign(@RequestBody List<Sign> signs){
        HashMap<String, Object> map = new HashMap<>();
        String result = signService.addSign(signs);
        map.put("data",result);
        return CommonResult.success(map);
    }

    @PostMapping("/checkSign")
    public CommonResult checkSign(@RequestBody Sign sign){
        HashMap<String, Object> map = new HashMap<>();
        boolean isExist = signService.checkSign(sign);
        String result;
        if (isExist){
            result = "success";
        } else {
            result = "false";
        }
        map.put("data",result);
        return CommonResult.success(map);
    }

    @GetMapping("/getSignList")
    public CommonResult getSignList(@RequestParam Map<String, Object> data){
        HashMap<String, Object> map = new HashMap<>();
        List<Sign> signs = signService.getSignList(data);
        int count = signService.getSelectCount(data);
        Page page = new Page();
        page.setList(signs);
        page.setTotal(count);
        map.put("list",signs);
        map.put("count",count);
        return CommonResult.success(map);
    }

    @GetMapping("/getSignById")
    public CommonResult getSignById(@RequestParam Integer id){
        HashMap<String, Object> map = new HashMap<>();
        Sign sign = signService.getSignById(id);
        map.put("data",sign);
        return CommonResult.success(map);
    }

    @PostMapping("/delSign")
    public CommonResult delSign(@RequestBody Sign sign){
        HashMap<String, Integer> map = new HashMap<>();
        int result = signService.delSign(sign);
        map.put("result",result);
        return CommonResult.success(map);
    }

    @PostMapping("/batchDeletion")
    public CommonResult batchDeletion(@RequestParam List<Integer> ids){
        HashMap<String, Object> map = new HashMap<>();
        String result = signService.batchDeletion(ids);
        map.put("data",result);
        return CommonResult.success(map);
    }

}
